package io.finer.erp.jeecg.bas.mapper;

import java.util.List;

import io.finer.erp.jeecg.bas.dto.ZrkShopOrderDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.finer.erp.jeecg.bas.dto.ZrkOrderProductDTO;
import io.finer.erp.jeecg.bas.dto.ZrkShopCustomerDTO;
import io.finer.erp.jeecg.bas.dto.ZrkShopTotalDTO;
import io.finer.erp.jeecg.bas.entity.ZrkShoporder;
import io.finer.erp.jeecg.bas.vo.ShopTotalVO;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * @Description: 商城订单信息表
 * @Author: jeecg-boot
 * @Date:   2020-08-22
 * @Version: V1.0
 */
public interface ZrkShoporderMapper extends BaseMapper<ZrkShoporder> {
	
	public ZrkShoporder selectByActiveDayPlan();
	public ZrkShoporder selectByActiveMonthPlan();
	public ZrkShoporder selectByActiveYearPlan();
	public ZrkShoporder selectNewOrOldCustomer(String customerId);
	
	/**
	 * 分页查询客户购买过的产品明细
	 * @param page
	 * @param customerName
	 * @return
	 */
	Page<ZrkShopCustomerDTO> selectCustomerAndProduct(IPage<ZrkShopCustomerDTO> page,@Param("customerName") String customerName);

	List<ShopTotalVO> queryShopTotal(@Param("customerName") String customerName);


	List<ZrkShoporder> getOrderByCustomerId(@Param("customerId")String  customerId);
	/*
	 * 获取已核销的
	 * @author libaow
	 * @date 2021/4/25 14:23
	 * @param customerId
	 */
	List<ZrkShoporder> getOrderHxYByCustomerId(@Param("customerId")String  customerId);


	/**
	 * 查询客户购买过的产品统计
	 * @param customerName
	 * @param orderTimeBegin
	 * @param orderTimeEnd
	 * @return
	 */
	List<ShopTotalVO> queryShopTotal(@Param("customerName") String customerName,@Param("orderTimeBegin") String orderTimeBegin,@Param("orderTimeEnd") String orderTimeEnd);

	/**
	 * 下单人销量统计查询
	 * @param creatBy
	 * @param orderTimeBegin
	 * @param orderTimeEnd
	 * @return
	 */
	List<ZrkOrderProductDTO> querySalesVolumeByUser(@Param("createBy") String[] createBy,@Param("orderTimeBegin") String orderTimeBegin,@Param("orderTimeEnd") String orderTimeEnd);

	
	@Select("SELECT COUNT(*) FROM (SELECT * FROM zrk_shoporder WHERE create_by=#{createBy} AND order_time BETWEEN #{orderTimeBegin} AND #{orderTimeEnd} GROUP BY customer_id) COUNT")
	int getCustomerCount(@Param("createBy") String createBy,@Param("orderTimeBegin") String orderTimeBegin,@Param("orderTimeEnd") String orderTimeEnd);

	Page<ZrkShopOrderDTO> listByModel(Page<ZrkShopOrderDTO> page,@Param("model") ZrkShoporder model);
}
